//Our includes
#include "Survey.h"
#include "Leg.h"


Survey::Survey() {

}

/*!
  \brief Deconstructor
  Does NOT delete any Legs that are added to this class on destruction.
  */
Survey::~Survey() {

}

/*!
 \brief Adds a Leg to the survey
 */
void Survey::AddLeg(Leg* Leg) {
    Legs.push_back(Leg);
}

/*!
\brief  Removes a Leg from the survey
The Leg is NOT delete from memory
*/
void Survey::RemoveLeg(Leg* leg) {
    std::vector<Leg*>::iterator iter;
    for(iter = Legs.begin(); iter != Legs.end(); iter++) {
        Leg* currentLeg = *iter;
        if(leg == currentLeg) {
            //Remove this Leg
            Legs.erase(iter);
        }
    }
}

/*!
 \brief Gets the Leg a the index

 Useful for iterating over the Legs.
 \code
 Survey survey();
 for(int i = 0; i < survey->GetNumberOfLegs(); i++) {
    Leg* Leg = survey->GetLeg(i);
 }
 \endcode
 */
Leg* Survey::GetLeg(int index) const {
    return Legs.at(index);
}

/*!
\brief Removes a child survey

This function does not delete survey from memory
*/
void Survey::RemoveChildSurvey(Survey* survey) {
    std::vector<Survey*>::iterator iter;
    for(iter = Surveys.begin(); iter != Surveys.end(); iter++) {
        Survey* currentSurvey = *iter;
        if(survey == currentSurvey) {
            //Remove the survey
            Surveys.erase(iter);
        }
    }
}
